//
//  HomeWeatherView.m
//  QuickCure1
//
//  Created by 李江波 on 2016/10/31.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "HomeWeatherView.h"
#import "Weather.h"

#import <UIImageView+WebCache.h>

@interface HomeWeatherView ()

@property (weak, nonatomic) IBOutlet UIImageView *img;

@property (weak, nonatomic) IBOutlet UILabel *weather;
@property (weak, nonatomic) IBOutlet UILabel *temperature;
@property (weak, nonatomic) IBOutlet UILabel *date;



@end


@implementation HomeWeatherView

+(instancetype)homeWeatherView{

    UINib *nib = [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
    
    return [[nib instantiateWithOwner:nil options:nil] lastObject];

}




-(void)setModel:(Weather *)model{

    _model = model;
    
    [self.img sd_setImageWithURL:[NSURL URLWithString:model.dayPictureUrl]];
    
     _img.layer.cornerRadius = 20;
     _img.layer.masksToBounds = YES;
//    _img.alpha = 0.5;
   
    
    self.weather.text = model.weather;
    
    
    //拆分字符
    NSArray *strArray = [model.temperature componentsSeparatedByString:@" "];
   
    NSString *min = [[strArray[2] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"-0123456789"]invertedSet]]componentsJoinedByString:@""];
    
    self.temperature.text = [NSString stringWithFormat:@"温度:%@ ~ %@°C",min,strArray[0]];
    
    NSDate *date = [NSDate date];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    formatter.dateFormat = @"yyyy-MM-dd";
    
    NSString *str = [formatter stringFromDate:date];
    
    self.date.text = [NSString stringWithFormat:@"日期:%@",str];
    

    
    
    
    
    /****************************************************/
    //1.创建动画对象
    /*
    
    //2.设置属性
    
    if ([model.weather isEqualToString:@"晴"]) {
        //2.基本动画  rotation
        CABasicAnimation *rotaBasic = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        //告诉系统要怎么动
        rotaBasic.toValue = @(M_PI  * 10);
        
        rotaBasic.duration = 10.0;
        rotaBasic.repeatCount = 100;
        [_img.layer addAnimation:rotaBasic forKey:@"keyFrame"];
        
    }else{
        
        CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 25, 0)];
        key.path = path.CGPath;
        key.duration = 3;
        key.repeatCount = CGFLOAT_MAX;
        //需要设置 匀速
        key.calculationMode = kCAAnimationPaced;
        //3.添加
        [_img.layer addAnimation:key forKey:@"keyFrame"];
    }
  */
    

}


@end
